package storage.v1;

import java.util.Collection;
import java.util.HashSet;

import com.onpositive.mediawiki.propertyparser.ParsedDocument;
import com.onpositive.units.ParsedProperty;

public class ReplacementRequest {
	
	private HashSet<String> targetSet = null ;	
	private boolean preserveTargetSet = true ;
	
	private boolean addNewProperties = true ;
	private boolean deleteLostProperties = false ;
	
	public ReplacementRequest(){}	
	
	public ReplacementRequest( Collection<String> strCol, 
							   boolean preserveTargetSet, boolean addNewProperties,	boolean deleteLostProperties) {
		super();
		this.targetSet = new HashSet<String>( strCol );
		this.preserveTargetSet = preserveTargetSet;
		this.addNewProperties = addNewProperties;
		this.deleteLostProperties = deleteLostProperties;
	}
	
	public void operate( ParsedDocument oldDoc, ParsedDocument newDoc )
	{
		oldDoc.getProps().clear() ;
		for( ParsedProperty prop : newDoc.getProps().values() )
			oldDoc.addProperty( prop ) ;
		//TODO implement this stuff
		//parents should be preserved
	}	
	public boolean addPropertyId( String id )
	{
		if( id == null )
			return false;
		
		if( targetSet == null )
			targetSet = new HashSet<String>() ;
		
		return targetSet.add( id ) ;
	}
	
	public boolean removePropertyId( String id )
	{
		if( id == null )
			return false;
		
		if( targetSet == null )
			targetSet = new HashSet<String>() ;
		
		return targetSet.remove( id ) ;		
	}
	
	public void addAll( Collection<String> strCol )	{
		
		if( strCol == null )
			return ;
		
		if( targetSet == null )
			targetSet = new HashSet<String>() ;
		
		targetSet.addAll( strCol ) ;	
	}

	public boolean isPreserveTargetSet() {
		return preserveTargetSet;
	}

	public void setPreserveTargetSet(boolean preserveTargetSet) {
		this.preserveTargetSet = preserveTargetSet;
	}

	public boolean isAddNewProperties() {
		return addNewProperties;
	}

	public void setAddNewProperties(boolean addNewProperties) {
		this.addNewProperties = addNewProperties;
	}

	public boolean isDeleteLostProperties() {
		return deleteLostProperties;
	}

	public void setDeleteLostProperties(boolean deleteLostProperties) {
		this.deleteLostProperties = deleteLostProperties;
	}
	
	
	

}
